package com.db.protocol.tags;

import com.db.protocol.exception.InvalidTagProtocolException;
import com.db.protocol.exception.ParseProtocolException;

/**
 *
 * @author nulls.narik
 */
public enum Tag {

    MSG_TYPE(35),
    CLIENT_ID(49),
    TICKER_SYMBOL(55),
    ORDER_SIDE(54),
    QUANTITY(38),
    PRICE(44),
    ORDER_TYPE(40),
    EXCHANGE_ID(30),
    TYPE_AGGREGATION(1);

    private final int tag;

    public int value() {
        return tag;
    }

    Tag(int tag) {
        this.tag = tag;
    }

    public static Tag parse(String message) throws ParseProtocolException {
        if (message == null) {
            throw new InvalidTagProtocolException(message);
        }
        try {
            int value = Integer.valueOf(message);

            for (Tag tag : values()) {
                if (tag.value() == value) {
                    return tag;
                }
            }
        } catch (NumberFormatException exception) {
            throw new InvalidTagProtocolException(message);
        }
        throw new InvalidTagProtocolException(message);
    }

}
